<?php
declare (strict_types=1);

namespace app\common\model;
use think\model\relation\BelongsTo;

class OrderProduct extends Base
{
    protected $name = 'order_product';

    public function product()
    {
        return $this->belongsTo(Product::class, 'pid', 'id')->with(['user']);
    }

    public function orders()
    {
        return $this->belongsTo(Order::class, 'order_id', 'id')->with(['user']);
    }

    public function productField()
    {
        return $this->hasOne(Product::class, 'id', 'pid')
            ->field('id,give_discount_amount,give_discount_pid,give_discount_day');
    }

    public function user(): BelongsTo
    {
        return $this->belongsTo(User::class, 'uid', 'id');
    }

}
